package com.jz.netthings.bloodsources.service.impl;

import com.jz.netthings.application.bodyCheck.bean.MyPage;
import com.jz.netthings.bloodsources.bean.XyFiveLink;
import com.jz.netthings.bloodsources.bean.XyReturnVisit;
import com.jz.netthings.bloodsources.mapper.XyFiveLinkMapper;
import com.jz.netthings.bloodsources.service.XyFiveLinkService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 五步链接记录 服务实现类
 * </p>
 *
 * @author 张凡
 * @since 2019-08-03
 */
@Service
public class XyFiveLinkServiceImpl extends ServiceImpl<XyFiveLinkMapper, XyFiveLink> implements XyFiveLinkService {
    @Autowired
    XyFiveLinkMapper xyFiveLinkMapper;
    @Override
    public MyPage<XyFiveLink> queryByCondition(Integer nurseId, String nurseName, String nurseDeptId, String providerName, String createTimeLess, String createTimeGreater, String linkTimeLess, String linkTimeGreater, String isComplete, String currentPage, String pageSize) throws AdscmSystemException {
        //XyReturnVisit
        MyPage<XyFiveLink> myPage=new MyPage<XyFiveLink>();
        myPage.setCurrentPageIndex(Integer.parseInt(currentPage));
        myPage.setPageSize(Integer.parseInt(pageSize));
        //对当前页参数currentPage 进行重新定义，为节省JVM资源开销，直接将计算后的开始页赋值给参数变量currentPage = beginIndex
        currentPage = myPage.getBeginIndex()+"";
        Integer count = xyFiveLinkMapper.queryByCount(nurseId,nurseName,nurseDeptId,providerName,createTimeLess,createTimeGreater,linkTimeLess,linkTimeGreater,isComplete);
        List<XyFiveLink> list  = xyFiveLinkMapper.queryByCondition(nurseId,nurseName,nurseDeptId,providerName,createTimeLess,createTimeGreater,linkTimeLess,linkTimeGreater,isComplete,Integer.parseInt(currentPage),Integer.parseInt(pageSize));
        //获取相关数据
        myPage.setItems(list);
        myPage.setTotal(count);
        return myPage;
    }

    @Override
    public Boolean updateXyFiveLinkInfo(XyFiveLink xyFiveLink) throws AdscmSystemException {
        boolean update = false;
        if(xyFiveLink!=null && xyFiveLink.getId()!=null){
            update =   super.updateById(xyFiveLink);
        }
        return update;
    }

    @Override
    public Boolean insertXyLinkInfo(XyFiveLink xyFiveLink, Token token) throws AdscmSystemException {
        boolean insert = false;
        if(xyFiveLink!=null){
            insert =  super.insert(xyFiveLink);
        }
        return  insert;
    }
}
